jconed.toolbar.register_handler ( 'Style', function ( editor )
{
	if ( ! jconed.config.styles ) return false;
	
	var options = [ { label: '(select)', value: '' } ];
	jconed.config.styles.iterate ( function ( s, v )
	{
		options.push ( { value: v, label: s } );
	} );

	var f = new liwe.form.instance ( 'jconed-style', 'no-action' );
	f.select ( { name: 'style', options: options, onchange: 'jconed.__style()' } );
	jconed.toolbar.set_context ( f.get () );
} );

jconed.__style = function ()
{
	var f = liwe.form.get ( 'jconed-style' );
	var style = f.get_value ( 'style' );
	if ( style == '' ) return;
	var selection = jconed.editor.get_selection ();
	selection.iterate ( function ( sel )
	{
		var span = document.createElement ( 'span' );
		span.className = style;
		sel.surroundContents ( span );
	} );
	return false;
};
